// post请求
function ajax(type, url, success, s) {
    if (window.XMLHttpRequest) {
        var oajax = new XMLHttpRequest();
    } else {
        var oajax = new ActiveXObject("Microsoft.XMLHTTP")
    }
    switch (type.toLowerCase()) {
        case 'get':
            oajax.open(type, url, true);
            oajax.send()
            break;
        case 'post':
            oajax.open(type, url, true);
            oajax.setRequestHeader("Content-Type", "application/json")
            oajax.send(JSON.stringify(s));
            break;
    }
    oajax.onreadystatechange = function () {
        if (oajax.readyState == 4) {
            if (oajax.status == 200 || oajax.status == 304) {
                success && success(oajax.responseText)
            }
        }
    }
}


function ajaxFile(file, url, success) {
    let fileInput = file.value;
    window.postmessage();
    let formData = new FormData();

    formData.append('file', fileInput);

    const xhr = new XMLHttpRequest();
    xhr.open('POST', url);
    xhr.withCredentials=true;
    xhr.setRequestHeader("Content-Type", "application/json")
    xhr.setRequestHeader("Origin", "");
    xhr.setRequestHeader("Referer", "");
    xhr.onload = function () {
        if (xhr.status === 200) {
            success && success(xhr.responseText);
        }
    };
    xhr.send(formData);


}



